import type { IAlbumItem } from "@/types/music/albumType";
import type { IHotSongItem } from "@/types/music/hotSongType";
import type { IMusicLyric } from "@/types/music/lyricType";
import type { IMusicMvUrl, IMusicPlayUrl } from "@/types/music/musicPlayerType";
import type { IPlayListDetail } from "@/types/music/playListType";
import type { ISearchHotWords } from "@/types/music/searchHotType";
import type { ISearchSongItem } from "@/types/music/searchSongType";
import type { ISingerItem } from "@/types/music/singerType";
import type { ISongListItem } from "@/types/music/songLIstType";
import type { ISuggsetItem } from "@/types/music/suggestSongType";
import { musicRequest } from "../index";
interface ISearchPayload {
  keywords: string;
  limit: number;
  offset: number;
}
// 获取最新热门歌曲
function getNewHotSongList() {
  return musicRequest.get<{
    code: number;
    category: number;
    result: IHotSongItem[];
  }>({
    url: "/personalized/newsong",
  });
}

// 搜索热搜榜
function searchHotList() {
  return musicRequest.get<{
    code: number;
    data: ISearchHotWords[];
    message: string;
  }>({
    url: "/search/hot/detail",
  });
}

// 搜索建议
function searchSuggestList(payload: { keywords: string; type: string }) {
  return musicRequest.get<{
    code: number;
    result: {
      allMatch: ISuggsetItem[];
    };
  }>({
    url: "/search/suggest",
    params: payload,
  });
}

// 搜索音乐
function searchMusic(payload: ISearchPayload) {
  return musicRequest.get<{
    result: {
      songs: ISearchSongItem[];
      hasMore: boolean;
      songCount: number;
    };
    code: number;
  }>({
    url: "/search",
    params: { type: 1, ...payload },
  });
}

// 搜索歌单
function searchMusicList(payload: ISearchPayload) {
  return musicRequest.get<{
    code: number;
    result: {
      playlists: ISongListItem[];
      hasMore: boolean;
    };
  }>({
    url: "/search",
    params: { type: 1000, ...payload },
  });
}

// 搜索歌手
function searchSinger(payload: ISearchPayload) {
  return musicRequest.get<{
    code: number;
    result: {
      hasMore: boolean;
      artists: ISingerItem[];
    };
  }>({
    url: "/search",
    params: { type: 100, ...payload },
  });
}

// 搜索专辑
function searchAlbum(payload: ISearchPayload) {
  return musicRequest.get<{
    result: {
      albums: IAlbumItem[];
      albumCount: number;
    };
    code: number;
  }>({
    url: "/search",
    params: { type: 10, ...payload },
  });
}

// 获取歌单详情
function getPlayListDetail(id: number) {
  return musicRequest.get<{
    code: number;
    playlist: IPlayListDetail;
  }>({
    url: "/playlist/detail",
    params: {
      id,
    },
  });
}

// 获取专辑详情
function getAlbumDetail(id: number) {
  return musicRequest.get<{
    code: number;
    songs: ISearchSongItem[];
    album: IAlbumItem;
  }>({
    url: "/album",
    params: {
      id,
    },
  });
}

// 获取歌曲详情：列表id获取
function getMusicDetailByListId(ids: string) {
  return musicRequest.get<{
    code: number;
    songs: ISearchSongItem[];
  }>({
    url: "/song/detail",
    params: {
      ids,
    },
  });
}

// 获取歌曲详情：指定id获取
function getMusicDetailById(ids: number) {
  return musicRequest.get<{
    code: number;
    songs: ISearchSongItem[];
  }>({
    url: "/song/detail",
    params: {
      ids,
    },
  });
}

// 获取歌手详情：歌手信息 + 热门歌曲
function getSingerDetail(id: number) {
  return musicRequest.get<{
    code: number;
    artist: ISingerItem;
    hotSongs: ISearchSongItem[];
  }>({
    url: "/artists",
    params: {
      id,
    },
  });
}

// 获取歌手详情：歌手专辑信息
function getSingerAlbum(payload: { id: number; offset?: number; limit?: number }) {
  return musicRequest.get<{
    code: number;
    more: true;
    hotAlbums: IAlbumItem[];
    artist: ISingerItem;
  }>({
    url: "/artist/album",
    params: payload,
  });
}

// 获取音乐的歌词
function getMusicLyric(id: number) {
  return musicRequest.get<IMusicLyric>({
    url: "/lyric",
    params: { id },
  });
}

// 获取音乐的播放地址
function getMusicPlayUrl(id: number) {
  return musicRequest.get<{
    code: number;
    data: IMusicPlayUrl[];
  }>({
    url: "/song/url",
    params: { id },
  });
}



export {
  getNewHotSongList,
  searchHotList,
  searchSuggestList,
  searchMusic,
  searchMusicList,
  searchSinger,
  searchAlbum,
  getPlayListDetail,
  getAlbumDetail,
  getMusicDetailByListId,
  getMusicDetailById,
  getSingerDetail,
  getSingerAlbum,
  getMusicLyric,
  getMusicPlayUrl,
};
